package com.esunny.resourcevisualization.controller;

import com.esunny.resourcevisualization.domain.entity.ResourceTypeEntityData;
import com.esunny.resourcevisualization.domain.response.ReturnStructure;
import com.esunny.resourcevisualization.service.ResourceTypeEntityDataService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version 1.0.0.0
 * @ClassName ResourceTypeEntityDataController
 * @Description 资源类别实体数据接口书写
 * @Author baochencong
 * @Date 2020/10/9 10:46
 */
@Controller
@RequestMapping("/resource")
public class ResourceTypeEntityDataController {

    @Resource
    private ResourceTypeEntityDataService resourceTypeEntityDataService;

    private static Logger LOGGER = LoggerFactory.getLogger(ResourceTypeEntityDataController.class);

    /**
     * 添加资源类别实体数据值
     *
     * @param resourceTypeEntityData 资源类别实体数据
     * @return 添加结果信息
     */
    @ResponseBody
    @PostMapping("/addResourceTypeEntityData")
    public ReturnStructure addResourceTypeEntityData(@RequestBody ResourceTypeEntityData resourceTypeEntityData) {
        if (resourceTypeEntityData == null) {
            return ReturnStructure.NOT_FOUND();
        }
        LOGGER.info("要添加的资源类别实体数据信息为：{}", resourceTypeEntityData);
        return resourceTypeEntityDataService.addResourceTypeEntityData(resourceTypeEntityData);
    }

    /**
     * 通过资源类别实体数据id修改资源类别实体数据值
     *
     * @param entityDataId    资源类别实体数据id
     * @param entityDataValue 资源类别实体数据值
     * @return 修改结果信息
     */
    @ResponseBody
    @PostMapping("/updateResourceTypeEntityDataByEntityDataId")
    public ReturnStructure updateResourceTypeEntityDataByEntityDataId(@RequestParam("entityDataId") int entityDataId, @RequestParam("entityDataValue") String entityDataValue) {
        if (StringUtils.isBlank(entityDataId + "") || StringUtils.isBlank(entityDataValue)) {
            return ReturnStructure.NOT_FOUND();
        }
        return resourceTypeEntityDataService.updateResourceTypeEntityDataByEntityDataId(entityDataId, entityDataValue);
    }

    /**
     * 通过资源类别实体id和资源类别实体字段英文名修改资源类别实体字段值
     *
     * @param resourceTypeEntityData 资源类别实体数据
     * @return 修改结果信息
     */
    @ResponseBody
    @PostMapping("/updateResourceTypeEntityDataByEntityIdAndFieldName")
    public ReturnStructure updateResourceTypeEntityDataByEntityIdAndFieldName(@RequestBody ResourceTypeEntityData resourceTypeEntityData) {
        if (resourceTypeEntityData == null) {
            return ReturnStructure.NOT_FOUND();
        }
        return resourceTypeEntityDataService.updateResourceTypeEntityDataByEntityIdAndFieldName(resourceTypeEntityData);
    }

    /**
     * 通过资源类别实体id和资源类别字段英文名获取资源类别实体字段值
     *
     * @param entityId  资源类别实体id
     * @param fieldName 资源类别实体字段英文名
     * @return 资源类别实体字段值
     */
    @ResponseBody
    @GetMapping("/getResourceTypeEntityDataByEntityIdAndFieldName/{entityId}/{fieldName}")
    public ReturnStructure getResourceTypeEntityDataByEntityIdAndFieldName(@PathVariable("entityId") int entityId, @PathVariable("fieldName") String fieldName) {
        if (StringUtils.isBlank(entityId + "") || StringUtils.isBlank(fieldName)) {
            return ReturnStructure.NOT_FOUND();
        }
        return ReturnStructure.SUCCESS("获取资源类别实体字段值成功", resourceTypeEntityDataService.getResourceTypeEntityDataByEntityIdAndFieldName(entityId, fieldName));
    }

    /**
     * 通过资源类别实体id获取资源类别实体字段值列表
     *
     * @param entityId 资源类别实体id
     * @return 资源类别实体字段值列表
     */
    @ResponseBody
    @GetMapping("/getResourceTypeEntityDataByEntityId/{entityId}")
    public ReturnStructure getResourceTypeEntityDataByEntityId(@PathVariable("entityId") int entityId) {
        if (StringUtils.isBlank(entityId + "")) {
            return ReturnStructure.NOT_FOUND();
        }
        return ReturnStructure.SUCCESS("获取资源类别实体字段值列表成功", resourceTypeEntityDataService.getResourceTypeEntityDataByEntityId(entityId));
    }
}
